import axios from 'axios'
import Vue from 'vue'
import { Toast } from 'vant';
import 'vant/lib/index.css';
Vue.use(Toast);

// 超时时间
//axios.defaults.timeout = 15000;
// axios.defaults.withCredentials=true;

// http请求拦截器
axios.interceptors.request.use(config => {

  Toast({
    type: 'loading',
    message: '加载中...',
    icon: '/static/loading.gif',
  })

  return config

}, error => {
  setTimeout(() => {
    Toast.clear();
  },10000)
  return Promise.reject(error)
})

// http响应拦截器
axios.interceptors.response.use(data => {// 响应成功关闭loading
  Toast.clear();
  return data
}, error => {
  setTimeout(() => {
    Toast.clear();
    Toast('请求失败');
  },5000)
  return Promise.reject(error)
})

export default axios;
